package com.shenzhenai.netease_handler_1_3_1_3;

import com.shenzhenai.netease_handler_1_3_1_3.core.Handler;
import com.shenzhenai.netease_handler_1_3_1_3.core.Looper;
import com.shenzhenai.netease_handler_1_3_1_3.core.Message;

import org.junit.Test;

/**
 * @author huangzehui
 * @date 26/4/2025 上午1:39 周六
 * @description
 */
public class ActivityThread {

    @Test
    public void main(){
        Looper.prepare();
        // 模拟Activity中，创建Handler对象
        final Handler handler = new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message msg) {
                System.out.println("hzhkkk : 1 = "+msg.obj.toString());
                return true;
            }
        }) {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                System.out.println("hzhkkk : 2 = "+msg.obj.toString());
            }
        };

        // 子线程发送消息
        new Thread(new Runnable() {
            @Override
            public void run() {
                Message message = new Message();
                message.obj = "hello net163";
                handler.sendMessage(message);
            }
        }).start();

        Looper.loop();
    }

}
